﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Text;
using System.Xml;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using EQT.Model;

namespace EQT.Dal
{
    public partial class DaDept   
    {
        public int CreateDeptartment(MoDept entity)
        {
            string SQL_INSERT = "INSERT INTO Dept (Dept_ID," + (entity.ParentDeptId == "" ? "" : "Dep_Dept_ID,") + "Dept_Name ,Dept_Tel ,Dept_Manager_Code ,Rem ) VALUES "
            + "(@Dept_ID," + (entity.ParentDeptId == "" ? "" : "@Dep_Dept_ID,") + "@Dept_Name,@Dept_Tel,@Dept_Manager_Code,@Rem)";

            try
            {
                DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);

                if (entity.ParentDeptId != "")
                {
                    db.AddInParameter(dbCommand, "Dep_Dept_ID", DbType.String, entity.ParentDeptId);
                }
                db.AddInParameter(dbCommand, "Dept_ID", DbType.String, SequenceKeys.GenerateDeptID());
                //设置参数:Dept_Name	
                db.AddInParameter(dbCommand, "Dept_Name", DbType.String, entity.DeptName);
                //设置参数:Dept_Tel	
                db.AddInParameter(dbCommand, "Dept_Tel", DbType.AnsiString, entity.DeptTel);
                //设置参数:Dept_Manager_Code	
                db.AddInParameter(dbCommand, "Dept_Manager_Code", DbType.AnsiString, entity.DeptManagerCode);
                //设置参数:Rem	
                db.AddInParameter(dbCommand, "Rem", DbType.String, entity.Rem);

                return db.ExecuteNonQuery(dbCommand);
            }
            catch (DbException ex)
            {
                HandleDbException(ex);
            }
            return 0;

            
        }
        
    }
}

